﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace AIC_PN
{
    public partial class BaoCaoMau8 : MyFromBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPermission();
            if (!IsPostBack)
            {
                BindDataToControls();
                if (Request.QueryString["KyBaoCao"] != null)
                {
                    cboKyBaoCao.SelectedValue = Request.QueryString["KyBaoCao"];
                    cboKyBaoCao_SelectedIndexChanged(sender, e);
                }
            }
        }

        private void CheckPermission()
        {
            Dictionary<string, int> Role = MyCommon.CheckPermission("BaoCaoMau1");
            if (Role == null || Role["Xem"] == 0 || ((Role["Xem"] == 1 && Role["Sua"] == 0)))
            {
                Response.Redirect("Index.aspx?p=0");
            }
        }

        private void BindDataToControls()
        {
            if (Session["userid"] != null)
            {
                string sql = "Select DV.* " +
                             "From tblDonVi DV " +
                             "Inner Join tblUser U On U.DonViID=DV.ID " +
                             "Where U.ID=" + Session["userid"];
                DataTable dtDV = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
                tdTenDonVi.InnerHtml = "<b><i>Đơn vị báo cáo : " + dtDV.Rows[0]["TenDV"] + "</i></b>";
                sql = "Select ID,TenDM From tblDanhMuc Where MaDM='" + MyConst.DanhMuc.KyBaoCao.Ma + "' ";
                SqlDataReader reKyBaoCao = SqlHelper.ExecuteReader(CommandType.Text, sql);
                clsDataBind.CreateCombo("Tất cả", reKyBaoCao, cboKyBaoCao, 1, 0);
            }
        }

        protected void BindDataToTextField()
        {
            string sql = "SELECT CM_TenBaoCao,CM_ThoiGianBaoCao FROM dbo.tblBaoCaoMau8 WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND IsCommon = 1";
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParameters.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParameters);
            if (dt.Rows.Count != 0)
            {
                txtTenBaoCao.Text = dt.Rows[0]["CM_TenBaoCao"].ToString();
                txtNgayBaoCao.Text = dt.Rows[0]["CM_ThoiGianBaoCao"].ToString();
            }
        }

        private void BindDataToGrid()
        {
            List<SqlParameter> lstParams = new List<SqlParameter>();
            lstParams.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
            lstParams.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, Session["userdonvi"]));
            lstParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));

            string sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData.DataSource = dt;
            grvData.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =2";
            DataTable dt2 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData2.DataSource = dt2;
            grvData2.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =3";
            DataTable dt3 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData3.DataSource = dt3;
            grvData3.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =4";
            DataTable dt4 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData4.DataSource = dt4;
            grvData4.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =5";
            DataTable dt5 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData5.DataSource = dt5;
            grvData5.DataBind();

            sql = "SELECT M1.ID,M1.KyBaoCaoID_DM,M1.DonViID,M1.TenBaoCaoID_DM,M1.F1,M1.F2,M1.F3,M1.F4,M1.F5,M1.F6,M1.F7,M1.IsCommon,M1.UserID,B.TenDM AS DMCha,A.TenDM,A.DVT,A.BoiDen,A.STT " +
            "FROM dbo.tblBaoCaoMau8 M1 INNER JOIN dbo.tblDanhMucBaoCao A ON M1.TenBaoCaoID_DM = A.ID " +
            "INNER JOIN dbo.tblDanhMucBaoCao B ON A.FatherID = B.ID " +
            "WHERE KyBaoCaoID_DM = @KyBaoCaoID_DM AND DonViID = @DonViID AND A.BoiDen =7";
            DataTable dt7 = SqlHelper.ExecuteDataTable(CommandType.Text, sql, lstParams);
            grvData7.DataSource = dt7;
            grvData7.DataBind();

            btnLuu.Visible = true;
            grvData.Visible = true;
            grvData2.Visible = true;
            grvData3.Visible = true;
            grvData4.Visible = true;
            grvData5.Visible = true;
            grvData7.Visible = true;
        }

        public void MergeRows(GridView gridView)
        {
            for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
            {
                GridViewRow row = gridView.Rows[rowIndex];
                GridViewRow previousRow = gridView.Rows[rowIndex + 1];

                if (row.Cells[0].Text == previousRow.Cells[0].Text)
                {
                    row.Cells[0].RowSpan = previousRow.Cells[0].RowSpan < 2 ? 2 : previousRow.Cells[0].RowSpan + 1;
                    previousRow.Cells[0].Visible = false;
                }
                if (row.Cells[0].Text.Trim() == previousRow.Cells[0].Text.Trim() && row.Cells[0].Text.Trim() == row.Cells[1].Text.Trim())
                {
                    row.Visible = false;
                }
            }
        }

        #region Events

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Index.aspx");
        }

        protected void cboKyBaoCao_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboKyBaoCao.SelectedIndex > 0)
            {
                btnLuu.Visible = false;
                grvData.Visible = false;
                grvData.EditIndex = -1;
                BindDataToGrid();
                if (((DataTable)grvData.DataSource).Rows.Count == 0)
                {
                    SqlTransaction MyTran = SqlHelper.BeginTransaction();
                    try
                    {
                        List<SqlParameter> lstParams = new List<SqlParameter>();
                        lstParams.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, cboKyBaoCao.SelectedValue));
                        lstParams.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, Session["userdonvi"]));
                        lstParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                        string sql = "INSERT INTO dbo.tblBaoCaoMau8( KyBaoCaoID_DM ,DonViID ,TenBaoCaoID_DM ,F1,IsCommon,UserID)   " +
                                 "SELECT @KyBaoCaoID_DM ,@DonViID ,B.ID,0,0,@UserID FROM dbo.tblDanhMucBaoCao A " +
                                 "INNER JOIN dbo.tblDanhMucBaoCao B ON A.ID = B.FatherID WHERE B.MaDM = 102";
                        SqlHelper.ExecuteNonQuery(System.Data.CommandType.Text, sql, lstParams);
                        sql = "INSERT INTO dbo.tblBaoCaoMau8(KyBaoCaoID_DM,DonViID,IsCommon ,UserID) " +
                              "VALUES( @KyBaoCaoID_DM,@DonViID,1,@UserID)";
                        SqlHelper.ExecuteNonQuery(System.Data.CommandType.Text, sql, lstParams);
                        MyTran.Commit();
                    }
                    catch
                    {
                        MyTran.Rollback();
                    }
                    grvData.EditIndex = -1;
                    BindDataToGrid();
                }
                else
                {
                    BindDataToTextField();
                    grvData.Visible = true;
                }
            }
            else
            {
                btnLuu.Visible = false;
                grvData.Visible = false;

            }
        }

        protected void btnLuu_Click(object sender, EventArgs e)
        {

            string sSQL = "Update tblBaoCaoMau8 Set CM_TenBaoCao=@CM_TenBaoCao,CM_ThoiGianBaoCao=@CM_ThoiGianBaoCao" +
                            " Where IsCommon=1 And DonViID=" + MyCommon.GetDonViID(Session["userid"].ToString()) + " And KyBaoCaoID_DM=" + cboKyBaoCao.SelectedValue;

            List<SqlParameter> lstParameter = new List<SqlParameter>();
            lstParameter.Add(SqlHelper.CreateParameterObject("@CM_TenBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtTenBaoCao.Text.Trim()));
            lstParameter.Add(SqlHelper.CreateParameterObject("@CM_ThoiGianBaoCao", SqlDbType.NVarChar, ParameterDirection.Input, txtNgayBaoCao.Text.Trim()));


            SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);

            MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);

        }

        private static void AddMergedCells(GridViewRow objgridviewrow, TableCell objtablecell, int colspan, int rowspan, string celltext)
        {
            objtablecell = new TableCell();
            objtablecell.Text = celltext;
            objtablecell.ColumnSpan = colspan;
            objtablecell.RowSpan = rowspan;
            objtablecell.HorizontalAlign = HorizontalAlign.Center;
            objgridviewrow.Cells.Add(objtablecell);
        }
        #endregion Events

        #region GridCommand 1
        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData.Rows[grvData.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData);
        }
        #endregion GridCommand 1

        #region GridCommand 2

        protected void grvData2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData2.Rows[grvData2.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData2.Rows[grvData2.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData2_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData2.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData2_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData2_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        #endregion GridCommand 2

        #region GridCommand 3

        protected void grvData3_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData3_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData3.Rows[grvData3.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData3.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData3_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData3.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData3_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData3_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData3.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData3_PreRender(object sender, EventArgs e)
        {

        }

        protected void grvData3_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        #endregion GridCommand 3

        #region GridCommand 4

        protected void grvData4_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData4_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[2].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData4.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData4_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData4_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData4_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData4.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData4_PreRender(object sender, EventArgs e)
        {

        }

        protected void grvData4_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        #endregion

        #region GridCommand 5

        protected void grvData5_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData5_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[1].Controls[0];
                TextBox txtF2 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[2].Controls[0];
                TextBox txtF3 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[3].Controls[0];
                TextBox txtF4 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[4].Controls[0];
                TextBox txtF5 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[5].Controls[0];
                TextBox txtF6 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[6].Controls[0];
                TextBox txtF7 = (TextBox)grvData5.Rows[grvData5.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F6", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF6.Text.Equals("") ? "0" : txtF6.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F7", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF7.Text.Equals("") ? "0" : txtF7.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[F6]=@F6,[F7]=@F7,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData5.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData5_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData5.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData5_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData5_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData5.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData5_PreRender(object sender, EventArgs e)
        {

        }

        protected void grvData5_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "24. Các nguồn vay");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Số vốn vay");
                AddMergedCells(objgridviewrow, objtablecell, 3, 1, "Số gia đình PN được vay vốn");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Số tổ, nhóm PN được váy vốn");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Tỷ lệ hoàn trả vốn");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Số vốn vay mới trong kỳ báo cáo");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Dư nợ hiện tại");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Số gia đình được vay vốn mới");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tổng số GĐ đang được vay");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "Tổng số tiền");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }

        #endregion

        #region GridCommand 6

        protected void grvData6_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData6_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData6_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData6_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData6_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData6_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData6_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion

        #region GridCommand 7

        protected void grvData7_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData7_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData7.Rows[grvData7.EditIndex].Cells[1].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData7.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData7_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData7.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData7_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData7_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData7.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData7_PreRender(object sender, EventArgs e)
        {

        }

        protected void grvData7_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        #endregion

        #region GridCommand 8
        protected void grvData8_RowCreated(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Xuất sắc");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Khá");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Trung bình");
                AddMergedCells(objgridviewrow, objtablecell, 2, 1, "Yếu");
                AddMergedCells(objgridviewrow, objtablecell, 1, 1, "Không xếp loại");
                AddMergedCells(objgridviewrow, objtablecell, 1, 2, "Sửa");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x00, 0x45, 0x8A);
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objgridviewrow.Font.Bold = true;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "S.lượng");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "%");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "S.lượng");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "%");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "S.lượng");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "%");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "S.lượng");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 1, "%");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x00, 0x45, 0x8A);
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objgridviewrow2.Font.Bold = true;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);
            }
        }

        protected void grvData8_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            RowDataBound(sender, e);
        }

        protected void grvData8_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;


            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                SqlTransaction MyTrans = SqlHelper.BeginTransaction();
                try
                {

                    // cap nhat vao database
                    TextBox txtF1 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF1");
                    TextBox txtF2 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF2");
                    TextBox txtF3 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF3");
                    TextBox txtF4 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF4");
                    TextBox txtF5 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF5");
                    TextBox txtF6 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF6");
                    TextBox txtF7 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF7");
                    TextBox txtF8 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF8");
                    TextBox txtF9 = (TextBox)grvData8.Rows[grvData8.EditIndex].FindControl("txtF9");

                    string sSQL = "UPDATE dbo.tblBaoCaoMau8 " +
                                  "SET F1=@F1,F2=@F2,F3=@F3,F4=@F4,F5=@F5,F6=@F6,F7=@F7,F8=@F8,F9=@F9" +
                                  ",UpdateDate = GETDATE(),UserID = @UserID WHERE ID = @ID";

                    List<SqlParameter> lstParameter = new List<SqlParameter>();

                    lstParameter.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, txtF1.Text.Trim().Equals("") ? "0" : txtF1.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, txtF2.Text.Trim().Equals("") ? "0" : txtF2.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, txtF3.Text.Trim().Equals("") ? "0" : txtF3.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, txtF4.Text.Trim().Equals("") ? "0" : txtF4.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, txtF5.Text.Trim().Equals("") ? "0" : txtF5.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F6", SqlDbType.Float, ParameterDirection.Input, txtF6.Text.Trim().Equals("") ? "0" : txtF6.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F7", SqlDbType.Float, ParameterDirection.Input, txtF7.Text.Trim().Equals("") ? "0" : txtF7.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F8", SqlDbType.Float, ParameterDirection.Input, txtF8.Text.Trim().Equals("") ? "0" : txtF8.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F9", SqlDbType.Float, ParameterDirection.Input, txtF9.Text.Trim().Equals("") ? "0" : txtF9.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, sID));

                    SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);
                    MyTrans.Commit();
                    grvData8.EditIndex = -1;
                    BindDataToGrid();
                    MyCommon.AddMessage(this.Master, "Cập nhật thành công", MyConst.MessageType.Success);
                }
                catch (Exception)
                {
                    MyTrans.Rollback();
                }
            }
            else if (e.CommandName == AIC_PN.MyConst.Action.Addnew)
            {
                SqlTransaction MyTrans = SqlHelper.BeginTransaction();
                try
                {
                    TextBox txtF1New = (TextBox)grvData8.FooterRow.FindControl("txtF1New");
                    TextBox txtF2New = (TextBox)grvData8.FooterRow.FindControl("txtF2New");
                    TextBox txtF3New = (TextBox)grvData8.FooterRow.FindControl("txtF3New");
                    TextBox txtF4New = (TextBox)grvData8.FooterRow.FindControl("txtF4New");
                    TextBox txtF5New = (TextBox)grvData8.FooterRow.FindControl("txtF5New");
                    TextBox txtF6New = (TextBox)grvData8.FooterRow.FindControl("txtF6New");
                    TextBox txtF7New = (TextBox)grvData8.FooterRow.FindControl("txtF7New");
                    TextBox txtF8New = (TextBox)grvData8.FooterRow.FindControl("txtF8New");
                    TextBox txtF9New = (TextBox)grvData8.FooterRow.FindControl("txtF9New");

                    string sql = "INSERT INTO dbo.tblBaoCaoMau8( KyBaoCaoID_DM ,DonViID ,F1 ,F2 ,F3 ,F4 ,F5 ,F6 ,F7 ,F8 ,F9 ,CreateDate ,UpdateDate ,UserID, LaToChuc) " +
                                 "VALUES  ( @KyBaoCaoID_DM,@DonViID ,@F1,@F2,@F3,@F4,@F5,@F6,@F7,@F8,@F9,GETDATE(),GETDATE(),@UserID, 0)";
                    List<SqlParameter> lstParameter = new List<SqlParameter>();
                    lstParameter.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(cboKyBaoCao.SelectedValue)));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@DonViID", SqlDbType.Int, ParameterDirection.Input, MyCommon.GetDonViID(Session["userid"].ToString())));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, txtF1New.Text.Trim().Equals("") ? "0" : txtF1New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, txtF2New.Text.Trim().Equals("") ? "0" : txtF2New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, txtF3New.Text.Trim().Equals("") ? "0" : txtF3New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, txtF4New.Text.Trim().Equals("") ? "0" : txtF4New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, txtF5New.Text.Trim().Equals("") ? "0" : txtF5New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F6", SqlDbType.Float, ParameterDirection.Input, txtF6New.Text.Trim().Equals("") ? "0" : txtF6New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F7", SqlDbType.Float, ParameterDirection.Input, txtF7New.Text.Trim().Equals("") ? "0" : txtF7New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F8", SqlDbType.Float, ParameterDirection.Input, txtF8New.Text.Trim().Equals("") ? "0" : txtF8New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@F9", SqlDbType.Float, ParameterDirection.Input, txtF9New.Text.Trim().Equals("") ? "0" : txtF9New.Text.Trim()));
                    lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(Session["userid"].ToString())));

                    int Result = SqlHelper.ExecuteNonQuery(CommandType.Text, sql, lstParameter);
                    if (Result == 0)
                    {
                        MyCommon.AddMessage(this.Master, "Có lỗi xảy ra trong quá trình thêm mới", MyConst.MessageType.Error);
                    }
                    else
                    {
                        MyCommon.AddMessage(this.Master, "Thêm mới thành công !", MyConst.MessageType.Success);
                    }

                    MyTrans.Commit();
                    BindDataToGrid();
                }
                catch (Exception)
                {
                    MyCommon.AddMessage(this.Master, "Có lỗi xảy ra trong quá trình thêm mới", MyConst.MessageType.Error);
                    MyTrans.Rollback();
                }
            }
            else if ((sCommandName == AIC_PN.MyConst.Action.Delete))
            {
                string sql = "DELETE FROM dbo.tblBaoCaoMau8 WHERE ID = @ID";
                List<SqlParameter> lstParameter = new List<SqlParameter>();

                lstParameter.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, sID));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, lstParameter);

                grvData8.EditIndex = -1;
                BindDataToGrid();
                MyCommon.AddMessage(this.Master, "Xóa thành công !", MyConst.MessageType.Success);
            }
        }

        protected void grvData8_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData8.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData8_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData8.EditIndex = -1;
            BindDataToGrid();
        }
        #endregion

        #region GridCommand 9

        protected void grvData9_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData9_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData9_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData9_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData9_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData9_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData9_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 10

        protected void grvData10_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData10_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData10_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData10_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData10_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData10_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData10);
        }

        protected void grvData10_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 11

        protected void grvData11_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData11_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData11.Rows[grvData11.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData11_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData11.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData11_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData11_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData11.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData11_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData11);
        }

        protected void grvData11_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 12

        protected void grvData12_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData12_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData12.Rows[grvData12.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData12_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData12_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData12_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData12_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData12_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 13

        protected void grvData13_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData13_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData13_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData13_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData13_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData13_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData13_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 14

        protected void grvData14_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData14_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData14_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData14_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData14_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData14_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData14);
        }

        protected void grvData14_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 15

        protected void grvData15_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData15_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData15_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData15_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData15_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData15_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData15_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion
        #region GridCommand 16

        protected void grvData16_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].ColumnSpan = 2;
                e.Row.Cells[1].Visible = false;
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dtr = (DataRowView)e.Row.DataItem;
                if (e.Row.Cells[0].Text.Equals(e.Row.Cells[1].Text))
                {
                    e.Row.Cells[0].ColumnSpan = 2;
                    e.Row.Cells[0].Text = (dtr.Row.ItemArray[11].ToString().Equals("0") ? "" : " ") + e.Row.Cells[0].Text;
                    e.Row.Cells[0].Font.Bold = !dtr.Row.ItemArray[11].ToString().Equals("0") ? true : false;
                    e.Row.Cells[1].Visible = false;
                }
                //string[] BoiDen = dtr.Row.ItemArray[10].ToString().Split(',');
                //if (BoiDen.Length >= 1)
                //{
                //    if (!BoiDen[0].Equals(""))
                //    {
                //        for (int i = 0; i < BoiDen.Length; i++)
                //        {

                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].BackColor = System.Drawing.Color.LightGray;
                //            e.Row.Cells[Convert.ToInt32(BoiDen[i]) + 1].Enabled = false;
                //        }
                //    }
                //}
            }
            RowDataBound(sender, e);
        }

        protected void grvData16_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string sID = e.CommandArgument.ToString().Trim();
            string sCommandName = e.CommandName;

            if ((sCommandName == AIC_PN.MyConst.Action.Approve))
            {
                List<SqlParameter> arrParams = new List<SqlParameter>();
                TextBox txtF1 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[3].Controls[0];
                TextBox txtF2 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[4].Controls[0];
                TextBox txtF3 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[5].Controls[0];
                TextBox txtF4 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[6].Controls[0];
                TextBox txtF5 = (TextBox)grvData4.Rows[grvData4.EditIndex].Cells[7].Controls[0];
                arrParams.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF1.Text.Equals("") ? "0" : txtF1.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF2.Text.Equals("") ? "0" : txtF2.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF3.Text.Equals("") ? "0" : txtF3.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF4.Text.Equals("") ? "0" : txtF4.Text)));
                arrParams.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, Convert.ToInt32(txtF5.Text.Equals("") ? "0" : txtF5.Text)));
                string sql = "UPDATE tblBaoCaoMau8 SET [F1]=@F1,[F2]=@F2,[F3]=@F3,[F4]=@F4,[F5]=@F5,[UpdateDate]=GETDATE(),[UserID]=@UserID WHERE ID=@ID ";
                arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Session["userid"]));
                arrParams.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(sID)));
                SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
                MyCommon.AddMessage(this.Master, "Cập nhật báo cáo thành công !", MyConst.MessageType.Success);
                grvData2.EditIndex = -1;
                BindDataToGrid();
            }
        }

        protected void grvData16_RowEditing(object sender, GridViewEditEventArgs e)
        {

            grvData4.EditIndex = e.NewEditIndex;
            BindDataToGrid();
        }

        protected void grvData16_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //grvData.PageIndex = e.NewPageIndex;
            //BindDataToGrid();
        }

        protected void grvData16_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grvData2.EditIndex = -1;
            BindDataToGrid();
        }

        protected void grvData16_PreRender(object sender, EventArgs e)
        {
            MergeRows(grvData2);
        }

        protected void grvData16_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {

                GridView objGridView = (GridView)sender;
                //GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow2 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
                GridViewRow objgridviewrow3 = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);

                TableCell objtablecell = new TableCell();
                AddMergedCells(objgridviewrow, objtablecell, 2, 3, "NỘI DUNG");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "ĐƠN VỊ TÍNH");
                AddMergedCells(objgridviewrow, objtablecell, 1, 3, "TỔNG SỐ");
                AddMergedCells(objgridviewrow, objtablecell, 4, 1, "TRONG TỔNG SỐ");
                objgridviewrow.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow.Font.Bold = true;
                objgridviewrow.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "BIÊN CHẾ");
                AddMergedCells(objgridviewrow2, objtablecell, 1, 2, "NỮ");
                AddMergedCells(objgridviewrow2, objtablecell, 2, 1, "DÂN TỘC");
                objgridviewrow2.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow2.Font.Bold = true;
                objgridviewrow2.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(1, objgridviewrow2);

                objtablecell = new TableCell();
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "TỔNG SỐ");
                AddMergedCells(objgridviewrow3, objtablecell, 1, 1, "NỮ");
                objgridviewrow3.BackColor = System.Drawing.Color.FromArgb(0x10, 0x9A, 0xEA);
                objgridviewrow3.Font.Bold = true;
                objgridviewrow3.ForeColor = System.Drawing.Color.White;
                objGridView.Controls[0].Controls.AddAt(2, objgridviewrow3);
            }
        }

        #endregion


    }
}
